﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common;

namespace WCFClient.Commands
{
    public abstract class ConsoleCommand
    {
        private static ConsoleCommand[] commands;
        protected static IMessage _pipeProxy;

        public abstract void execute(String[] args);

        public static ConsoleCommand create(String cmd,IMessage pipeProxy)
        {
            if (commands == null)
                commands = new ConsoleCommand[17];
            if (pipeProxy == null)
                _pipeProxy = pipeProxy;
            switch (cmd)
            {
                case "choose":
                    if (commands[0] == null)
                        return commands[0] = new Choose();
                    else return commands[0];
                case "back":
                    if (commands[1] == null)
                        return commands[1] = new Back();
                    else return commands[0];
                case "addPost":
                    if (commands[2] == null)
                        return commands[2] = new AddPost();
                    else return commands[2];
                case "addThread":
                    if (commands[3] == null)
                        return commands[3] = new AddThread();
                    else return commands[3];
                case "addSubForum":
                    if (commands[4] == null)
                        return commands[4] = new AddSubForum();
                    else return commands[4];
                case "removeSubForum":
                    if (commands[5] == null)
                        return commands[5] = new RemoveSubForum();
                    else return commands[5];
                case "removeThread":
                    if (commands[6] == null)
                        return commands[6] = new RemoveThread();
                    else return commands[6];
                case "removePost":
                    if (commands[7] == null)
                        return commands[7] = new RemovePost();
                    else return commands[7];
                case "editPost":
                    if (commands[8] == null)
                        return commands[8] = new EditPost();
                    else return commands[8];
                case "editThread":
                    if (commands[9] == null)
                        return commands[9] = new EditThread();
                    else return commands[9];
                case "addModerator":
                    if (commands[10] == null)
                        return commands[10] = new AddModerator();
                    else return commands[10];
                case "removeModerator":
                    if (commands[11] == null)
                        return commands[11] = new RemoveModerator();
                    else return commands[11];
                case "changeModerator":
                    if (commands[12] == null)
                        return commands[12] = new ChangeModerator();
                    else return commands[12];
                case "userMessageCount":
                    if (commands[13] == null)
                        return commands[13] = new UserMessageCount();
                    else return commands[13];
                case "messageCount":
                    if (commands[14] == null)
                        return commands[14] = new MessageCount();
                    else return commands[14];
                case "logout":
                    if (commands[15] == null)
                        return commands[15] = new Logout();
                    else return commands[15];
                case "help":
                    if (commands[16] == null)
                        return commands[16] = new Help();
                    else return commands[16];
                default:
                    return null;
            }
        }
    }
}
